// shopPages/Replacement/Replacement.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodsInfo: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.order_id;
    var goods_id = options.goods_id;
    var that = this;
    that.setData({
      goods_id: options.goods_id,
      order_id: options.order_id
    });
    var url2 = '/order/exchange_details';
    var params2 = {
      id: id,
      goods_id:options.goods_id
    };
    app.HttpPostSend(url2, params2, function (res) {
      if (res.msg != "success") {
        app.showTipMsg(res.msg);
      } else {
        if (res.data) {

          var goodsInfo = res.data.goodsInfo;
          for (var i = 0; i < goodsInfo.length; i++) {
            goodsInfo[i].title = goodsInfo[i].title.slice(0, 12) + "...";
          }

          that.setData({
            goodsInfo: goodsInfo,
          })
        }
      }
    });
  },
  toGoodsDetail: function (e) {
    wx.navigateTo({
      url: "/pages/goodsDetail/goodsDetail?id=" + e.currentTarget.dataset.id
    })
  },
  bindTuihuo:function(e){
    console.log(e.currentTarget.dataset.refund_type);
    wx.redirectTo({
      url: "../Refund/Refund?order_id=" + this.data.order_id + "&goods_id=" + this.data.goods_id + "&img_url=" + this.data.goodsInfo[0].img_url + "&title=" + this.data.goodsInfo[0].title + "&key_name=" + this.data.goodsInfo[0].key_name+"&refund_type="+e.currentTarget.dataset.refund_type
    })
  },
  bindTuihuan: function () {
    wx.redirectTo({
      url: "../Exchange/Exchange?order_id=" + this.data.order_id + "&goods_id=" + this.data.goods_id + "&img_url=" + this.data.goodsInfo[0].img_url + "&title=" + this.data.goodsInfo[0].title + "&key_name=" + this.data.goodsInfo[0].key_name
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})